#include"DoubleLinkList.h"
#include<ctime>
#include<string.h>

struct Student
{
    Student(int id, const std::string name):id(id),name(name){}
    int id;
    std::string name;
};


void Print(void *p)
{
    Student *s = (Student *)p;
    std::cout << s->id << " " << s->name << std::endl;
}

void Free(void *p)
{
    Student *s = (Student *)p;
    delete s;
}

bool Compare(void *p1,void *p2)
{
    Student *s1 = (Student *)p1;
    Student *s2 = (Student *)p2;
    return s1->id == s2->id;
}

bool Greater(void *p1,void *p2)
{
    Student *s1 = (Student *)p1;
    Student *s2 = (Student *)p2;
    return s1->id > s2->id;    
}

DoubleLinkList::ElementType CopyData(void *p)
{
    Student *s = (Student *)p;
    s = new Student(s->id,s->name);
    return s;
}

int main()
{    
    DoubleLinkList a;
    Student *s1 = new Student(1,"zhangsan");
    Student *s2 = new Student(2,"lisi");
    Student *s3 = new Student(3,"wangwu");
    a.SetFreeFunc(Free);
    a.SetCopyDataFunc(CopyData);
    a.SetPrintFunc(Print);
    a.SetCompareFunc(Compare);
    a.SetGreaterFunc(Greater);
    a.InsertTail(s1);
    a.InsertTail(s2);
    a.InsertTail(s3);
    a.InsertTail(s3);
    a.InsertTail(s2);
    a.InsertTail(s1);

    a.UpdataByElement(s1,s3);
    a.show();



    // DoubleLinkList b;
    // b = a;
    // b.show();

    // DARRAY::DynamicArray array1;
    // array1.SetFreeFunc(Free);
    // array1.SetCopyDataFunc(CopyData);
    // array1.SetPrintFunc(Print);
    // array1.SetCompareFunc(Compare);
    // array1.SetGreaterFunc(Greater);
    // Student s1(1,"zhangsan");
    // Student s2(2,"lisi");
    // Student s3(3,"wangwu");
    // array1.InsertTail(s1);
    // array1.InsertTail(s2);
    // array1.InsertTail(s3);

    // array1.InsertTail(&s3);
    // array1.InsertTail(&s2);
    // array1.InsertTail(&s1);
    
    // array1.RemoveByElement(&s2);
    // array1.UpdataByElement(&s1,&s3);

    // DARRAY::DynamicArray array2 = array1;

    // DARRAY::DynamicArray array3 = array1.Merge(array2);
    // array3.SetFreeFunc(Free);
    // array3.SetCopyDataFunc(CopyData);
    // array3.SetPrintFunc(Print);
    // array3.SetCompareFunc(Compare);
    // array3.SetGreaterFunc(Greater);

    // array3.show();
    
    delete s1;
    delete s2;
    delete s3;
    return 0;
}